package xyz.penghaonan.p2plib.job.base;

public interface Operation<T> {
    void addListener(OperationListener listener);

    void removeListener(OperationListener listener);

    void run(Job job);

    void doOperation();

    void onFinish(Result<T> result);

    String getName();

    class Result<T> {
        public boolean success;
        public String msg;
        public T data;

        @Override
        public String toString() {
            return "Result{" +
                    "success=" + success +
                    ", msg='" + msg + '\'' +
                    ", data=" + data +
                    '}';
        }

        public static <T> Result<T> defaultResult() {
            Result<T> result = new Result<>();
            result.success = false;
            return result;
        }

        public static <T> Result<T> result(boolean success, String msg) {
            Result<T> result = new Result<>();
            result.success = success;
            result.msg = msg;
            return result;
        }
    }
}
